from selenium import  webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option("excludeSwitches", ["enable-automation"])
op.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options = op)

driver.get("http://news.baidu.com/")
xw = driver.find_elements(By.XPATH,"//*[@id='localnews-zixun']/ul/li[1]/a")
for a in xw:
    content = a.text
    a.click()
    all_handles = driver.window_handles
    driver.switch_to.window(all_handles[1])

    title = driver.title
    assert content in title

    sleep(2)
    driver.close()

    driver.switch_to.window(all_handles[0])
    sleep(2)
driver.quit()